/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Client_GUI;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.JXPanel;

/**
 *
 * @author 10520_000
 */
public class Unity {
    public static void AddPanel(JXPanel parent, JXPanel child){
        //remove all component in parent panel
        if(parent.getComponentCount() >0){
            parent.removeAll();
            parent.revalidate();
            parent.repaint();
        }
        
        //add component child into component parent
        child.setSize(parent.getSize());
        child.setPreferredSize(parent.getPreferredSize());
        child.setVisible(true);
        parent.add(child);
        parent.revalidate();
        parent.repaint();            
    }
    
    public static void showDialog(Component parent, String imagePath, String title, String message, Color color,int messageType,Object[] options){
//            
        JOptionPane j = new JOptionPane(message, messageType, messageType, null, options);
        j.setIcon(new ImageIcon(imagePath));
        j.setBackground(color);
        j.setForeground(color);
        j.setFont(new Font("Times New Roman", Font.CENTER_BASELINE, Font.ITALIC));
        JDialog dialog = j.createDialog(parent, title);
        dialog.show();
    }
    
    public static boolean CompareDate(String date1, String date2,int value) throws ParseException{
        SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
        Calendar day1 = Calendar.getInstance();

        Calendar day2 = Calendar.getInstance();

        day1.setTime(formater.parse(date1));
        day2.setTime(formater.parse(date2));
        day1.add(Calendar.DAY_OF_MONTH, value);
        return ( day1.compareTo(day2)<=0) ;
    }
}
